﻿using System.Xml.Linq;
using AutoMoq;
using LINQPad.Extensibility.DataContext;
using NUnit.Framework;
using FluentAssertions;

namespace MongoLP.Test
{
    [TestFixture]
    public class PropertiesTests
    {
        /// <summary>
        /// Test that our Properties class works as expected.
        /// Not all that concerned about the fact that we are checking 
        /// a lot of stuff in one test.  Properties is after all a 
        /// very simple class.
        /// </summary>
        [Test]
        public void PropertiesWork()
        {
            var mock = new AutoMoqer();
            mock.GetMock<IConnectionInfo>()
                .Setup(x => x.DriverData)
                .Returns(new XElement("DriverData"));
            mock.GetMock<IConnectionInfo>()
                .Setup(x => x.Persist)
                .Returns(false);

            var p = new Properties(mock.Resolve<IConnectionInfo>());
            const string actualConnectionString = "testconnectionstring";
            p.ConnectionString = actualConnectionString;
            p.ConnectionString.Should().Be(actualConnectionString);
            p.ConnectionString.Should().NotBe("somethingelse");

            const string actualPath = "there is no path";
            p.EntityAssemblyPath = actualPath;
            p.EntityAssemblyPath.Should().Be(actualPath);
            p.ConnectionString.Should().NotBe("somethingelse");

            const string actualInterface = "IEntity";
            p.EntityInterface = actualInterface;
            p.EntityInterface.Should().Be(actualInterface);
            p.ConnectionString.Should().NotBe("somethingelse");

            p.ConnectionInfo.Should().NotBeNull();

            p.ConnectionInfo.DriverData.Should().HaveElement("EntityInterface");
            p.ConnectionInfo.DriverData.Should().HaveElement("ConnectionString");
            p.ConnectionInfo.DriverData.Should().HaveElement("EntityAssemblyPath");

            p.Persist.Should().Be(false);
        }
    }
}
